//
//  UIButton+Extension.swift
//  sinaWeibo
//
//  Created by LSY on 15/12/21.
//  Copyright © 2015年 lsy. All rights reserved.
//

import UIKit

//抽取Button的方法

//实例化一个 有背景视图 + title 的自定义按钮
extension UIButton {

    convenience init (title:String,backImageName:String?,fontSize:CGFloat,color:UIColor,imageName:String? = nil) {
    
    self.init()
        
        //    需要调用本类的指定构造函数  实例化自己
//        设置image
        if imageName != nil{
        
            setImage(UIImage(named: imageName!), forState: .Normal)
        
        }
        
        if backImageName != nil{
        
            //       设置背景图片
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        
        }
        //        设置名字
        setTitle(title, forState:.Normal)
        //        设置textlable
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        //
        setTitleColor(color, forState: .Normal)
        sizeToFit()
        
//        瞎比写，坑死哥的bug
       
//        addTarget(self, action: "registorBtnClicke", forControlEvents: .TouchUpInside)
        
    }
    
    
    
//    返回一个 有背景视图 + image 按钮的样式
    
    convenience init(imageName:String,backgroundImage:String){
    
    self.init()
        
        setImage(UIImage(named:imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backgroundImage), forState: .Normal)
        setBackgroundImage(UIImage(named: backgroundImage+"_highlighted"), forState: .Highlighted)
        
        sizeToFit()

        
    }
    



}
